<?php

	class WebwiTask 
	{
		private $_scripts = array();
		private $interval = '60';
		
			public function getScript()
			{
				return $this->_scripts;
			}
				
				public function setScript($value)
				{
					$this->_scripts = $value;
				}
				
					public function getInterval()
					{
						return $this->interval;
					}
					
						public function setInterval($value)
						{
							$this->interval = $value;
						}
						
							public function setLastExecTime($value)
							{
								$this->_lastexec = $value;
							}
							
								  public function executeTask()
								  {
									  // * TODO: maybe we will load the working script right here and exec that after the querys
									  $script = $this->db->QuoteString($this->_scripts);
									  $this->db->query("UPDATE ".$this->db->prefix('tasks')." SET lastExecution = NOW() WHERE script = '".$script."'");
								  }
								  
								  
								  	public static function getOverWorked($limit = 1)
									{
										$res = array();
										$limit = $this->db->QuoteString($limit);
										
										$tasks = $this->db->numRows("SELECT * FROM " . $this->db->prefix('tasks') . " WHERE DATE_ADD(lastExecution, INTERVAL `interval` MINUTE) < NOW() or lastExecution IS NULL or DATE_ADD(lastExecution, INTERVAL `interval` MINUTE) IS NULL LIMIT 0," . $limit);
											foreach($tasks as $task)
											{
												$newTask = new WebwiTask();
												$newTask->setScript($task->script);
												$newTask->setInterval($task->interval);
												$newTask->setLastExecution($task->lastExecution);
												$res[] = $newTask;
											}
										return $res;
									}

	}//CLASSEND
?>					